package cn.dida.service.impl;

import cn.dida.dao.SalesmanPayruleDao;
import cn.dida.model.Pageable;
import cn.dida.model.SalesmanPayrule;
import cn.dida.model.SalesmanPayruleArea;
import cn.dida.model.SalesmanPayrulePro;
import cn.dida.service.SalesmanPayruleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


/**
 * Created by zhangzhiling on 2017/8/30.
 */
@Service
public class SalesmanPayruleServiceImpl implements SalesmanPayruleService {

    @Autowired
    private SalesmanPayruleDao salesmanPayruleDao;

    /**
     * 获取规则列表
     * @param companyId
     * @param name
     * @param adcode
     * @param state
     * @param page
     * @return
     */
    @Override
    public Pageable<SalesmanPayrule> queryList(Integer companyId, String name, String adcode, Integer state, Integer page) {
        return salesmanPayruleDao.queryList(companyId, name, adcode,state,page);
    }

    /**
     * 导出数据 列表
     * @param companyId
     * @param name
     * @param state
     * @return
     */
    @Override
    public List<SalesmanPayrule> exportList(Integer companyId, String name, Integer state){

        return salesmanPayruleDao.exportList(companyId,name,state);
    }

    /**
     * 添加支付规则
     * @param payrule
     * @return
     */
    @Override
    public Integer insertPayrule (SalesmanPayrule payrule){
        return salesmanPayruleDao.insertPayrule(payrule);
    }

    /**
     * 修改规则状态
     * @param baseId
     * @param state
     * @return
     */
    @Override
    public Integer updateState(Integer baseId,Integer state){
        return salesmanPayruleDao.updateState(baseId,state);
    }

    /**
     * 获取详情
     * @param baseId
     * @return
     */
    public SalesmanPayrule getDetail(Integer baseId){

        SalesmanPayrule salesmanPayrule = salesmanPayruleDao.get_payrule_base(baseId);
        if(salesmanPayrule == null){
            return null;
        }
        List<SalesmanPayrulePro> proList = salesmanPayruleDao.get_payrule_prod(baseId);
        List<SalesmanPayruleArea> areaList = salesmanPayruleDao.get_payrule_area(baseId);
        salesmanPayrule.setProList(proList);
        salesmanPayrule.setAreaList(areaList);
        return salesmanPayrule;
    }

    /**
     * 编辑提交
     * @param payrule
     * @return
     */
    @Override
    public Integer updatePayrule(SalesmanPayrule payrule){
        SalesmanPayrule salesmanPayrule = salesmanPayruleDao.get_payrule_base(payrule.getId());
        if(salesmanPayrule == null){
            return -1;
        }
        return salesmanPayruleDao.updatePayrule(payrule);
    }

    /**
     * 适用区域产品详情 列表
     * @param adcode
     * @param prodct
     * @param baseId
     * @param page
     * @return
     */
    public Pageable<Map<String,Object>> getProdAndAreaList(String adcode, String prodct,String area, String baseId,Integer state, Integer page){
        return salesmanPayruleDao.getProdAndAreaList(adcode,prodct,area,baseId,state,page);
    }

    /**
     * 启用验证
     * @param baseId
     * @return
     */
    public Boolean test(Integer baseId){
        return salesmanPayruleDao.test(baseId);
    }

    /**
     * 规则查询列表
     * @param prodct
     * @param area
     * @param state
     * @param page
     * @return
     */
    public Pageable<Map<String,Object>> payruleSearchList(Integer companyId,String prodct,String area,Integer state,Integer page){
        Pageable<Map<String,Object>> pageList = salesmanPayruleDao.payruleSearchList( companyId,prodct,area,state,page);
        return pageList;
    }

    /**
     * 规则查询列表 导出
     * @param companyId
     * @param prodct
     * @param area
     * @param state
     * @return
     */
    public List<Map<String,Object>> searchList_export(Integer companyId,String prodct,String area,Integer state){

        List<Map<String,Object>> list = salesmanPayruleDao.searchList_export( companyId,prodct,area,state);
        return list;
    }
}
